package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.core.domain.entity.Seal;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.ISealService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 印章Controller
 * 
 * @author ess
 * @date 2021-10-18
 */
@RestController
@RequestMapping("/system/seal")
public class SealController extends BaseController
{
    @Autowired
    private ISealService sealService;

    /**
     * 查询印章列表
     */
    @PreAuthorize("@ss.hasPermi('system:seal:list')")
    @GetMapping("/list")
    public TableDataInfo list(Seal seal)
    {
        startPage();
        List<Seal> list = sealService.selectSealList(seal);
        return getDataTable(list);
    }

    /**
     * 导出印章列表
     */
    @PreAuthorize("@ss.hasPermi('system:seal:export')")
    @Log(title = "印章", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Seal seal)
    {
        List<Seal> list = sealService.selectSealList(seal);
        ExcelUtil<Seal> util = new ExcelUtil<Seal>(Seal.class);
        return util.exportExcel(list, "印章数据");
    }

    /**
     * 获取印章详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:seal:query')")
    @GetMapping(value = "/{sealId}")
    public AjaxResult getInfo(@PathVariable("sealId") String sealId)
    {
        return AjaxResult.success(sealService.selectSealBySealId(sealId));
    }

    /**
     * 新增印章
     */
    @PreAuthorize("@ss.hasPermi('system:seal:add')")
    @Log(title = "印章", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Seal seal)
    {
        return toAjax(sealService.insertSeal(seal));
    }

    /**
     * 修改印章
     */
    @PreAuthorize("@ss.hasPermi('system:seal:edit')")
    @Log(title = "印章", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Seal seal)
    {
        return toAjax(sealService.updateSeal(seal));
    }

    /**
     * 删除印章
     */
    @PreAuthorize("@ss.hasPermi('system:seal:remove')")
    @Log(title = "印章", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sealIds}")
    public AjaxResult remove(@PathVariable String[] sealIds)
    {
        return toAjax(sealService.deleteSealBySealIds(sealIds));
    }
}
